//package io.github.nnkwrik.gateway.config;
//
//import org.springframework.cloud.gateway.filter.GatewayFilter;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.core.Ordered;
//import org.springframework.core.io.buffer.DataBuffer;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Flux;
//import reactor.core.publisher.Mono;
//
//import java.nio.charset.StandardCharsets;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//@Component
//public class VerificationFilter implements GatewayFilter, Ordered {
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//
//        String bodyContent = resolveBodyFromRequest(exchange.getRequest());
//
//        return chain.filter(exchange);
//    }
//
//    public static String resolveBodyFromRequest(ServerHttpRequest serverHttpRequest){
//        //获取请求体
//        Flux<DataBuffer> body = serverHttpRequest.getBody();
//        StringBuilder sb = new StringBuilder();
//
//        body.subscribe(buffer -> {
//            byte[] bytes = new byte[buffer.readableByteCount()];
//            buffer.read(bytes);
////            DataBufferUtils.release(buffer);
//            String bodyString = new String(bytes, StandardCharsets.UTF_8);
//            sb.append(bodyString);
//        });
//        return formatStr(sb.toString());
//    }
//
//    /**
//     * 去掉空格,换行和制表符
//     * @param str
//     * @return
//     */
//    private static String formatStr(String str){
//        if (str != null && str.length() > 0) {
//            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
//            Matcher m = p.matcher(str);
//            return m.replaceAll("");
//        }
//        return str;
//    }
//
//    @Override
//    public int getOrder() {
//        return 1;
//    }
//}
//
